<template>
  <view>
    <scratchcard ref="scratchcard" v-if="comName=='scratchcard'"></scratchcard>
    <wheel ref="wheel"  v-if="comName=='wheel'"></wheel>
	<poster ref="poster" v-if="comName=='poster'"></poster>
    <relay ref="relay" v-if="comName=='relay'"></relay>
    <worldGuess ref="sportsGuess" v-if="comName=='sports'"></worldGuess>
	<answer ref="answer" v-if="comName=='answer'"></answer>
	<collectWord v-if="comName=='collect'"></collectWord>
	<vote  v-if="comName=='vote'" @getData="getPageData"></vote>
	<drawlots  v-if="comName=='drawlots'"></drawlots>
	<cards v-if="comName=='cards'"></cards>
	<redpkg  v-if="comName=='redpkg'"></redpkg>
  </view>
</template>

<script>
	/**
	 * 关于token的设置   
	 * 任何页面的传参，都不可以使用’id‘字段为参数;id作为全局仅唯一的活动id，只能为当前活动的id，因为要设置唯一token，一旦使用id作为参数会出现跳转其他移动端 报错异常；生命周期异常执行
	 * app获取token设置写在main.js中
	 * 其他端执行均放在QFH5.js的     function  checklogin()
	 * */
// #ifdef H5
const comp = {};
const contexts = require.context('./allPlugin', false, /\.vue$/);
contexts.keys().forEach(key => {
  let name = key.slice(2, -4);
  comp[name] = contexts(key).default || contexts(key);
})
// #endif
// #ifdef MP-WEIXIN
import scratchcard from './allPlugin/scratchcard.vue'
import wheel from './allPlugin/wheel.vue'
import poster from './allPlugin/poster.vue'
import relay from './allPlugin/relay.vue'
import worldGuess from './allPlugin/worldGuess.vue'
import answer from './allPlugin/answer.vue'
import collectWord from './allPlugin/collectWord.vue'
import { Store } from 'vuex';
// #endif
import {proxyShareFun} from '@/until/QFH5.js'
export default {
  // #ifdef H5
  components: {...comp},
  // #endif
  // #ifdef MP-WEIXIN
  components: {scratchcard, wheel,poster, relay, worldGuess,answer,collectWord},
  // #endif
  data() {
    return {
      key: {},
      comName: null,
      comData:null
    }
  },
  methods:{
    getPageData(data){
      this.comData = data
    }
  },
  mounted() {
	// this.$store.dispatch('setSiteinfo')
    // console.log(comp)
    // #ifdef MP-WEIXIN
	
    // #endif
  },
  onPageScroll(e) {
	if(this.comName!='poster') return
    console.log('开始滚动')
    this.startMove = true
    this.$store.commit('SET_START_MOVE',this.startMove)
    clearTimeout(this.timer) //这里必须要每次滚动前 清除一次
    // 如果停留则表示滚动结束  一旦空了1s就判定为滚动结束
    this.timer = setTimeout(() => {
      console.log('结束滚动')
      this.startMove = false
      console.log(this.startMove)
      this.$store.commit('SET_START_MOVE',this.startMove)
    }, 500)
  },
  onLoad(op) {
    if (op.id) {
      this.actid = op.id
      uni.setStorageSync('actid', op.id)
    }
	//保存邀请码--助力
	if(op.invite){
		uni.setStorageSync(this.actid+'Invite', op.invite)
		uni.setStorageSync(this.actid+'Tid', op.tid)
	}else{
		uni.setStorageSync(this.actid+'Invite', 0)
		uni.setStorageSync(this.actid+'Tid', 0)
	}
    this.comName = op.plugin
    if('sports' == this.comName){
      if(op.race_id != ''){
        this.$store.commit('SET_RACE_ID', op.race_id)
      }
    }
    this.$store.commit('SETACTIVITYNAME', op.plugin)
	this.$store.commit('SETACTIVITYTYPE', op.type)
	
	
    uni.setStorageSync('WEB', null)
    if (op.web && op.web == 1) {
      console.log('set')
      uni.setStorageSync('actid', op.id || null)
      uni.setStorageSync('WEB', true)
    }
	
	
  },
  async onShow() {
    // #ifdef MP-WEIXIN
    let mp = requireMiniProgram()
    const siteInfo = await mp.getSiteInfo()
    this.$store.commit('setHost', siteInfo.request_host)
    global.baseURI = siteInfo.reverse_proxy_domain
    // this.$store.dispatch('setSiteinfo')

    // let mp = requireMiniProgram()
    const pages = getCurrentPages();
    const currentPage = pages[pages.length - 1];
    const url = `/${currentPage.route}`;
    console.log('登录url', url, currentPage.data.id)

    // #endif
	//设置标题
    let title = uni.getStorageSync('title') || ''
    this.$setTitle(title)
	if(this.comName == 'sports'){
      console.info(this.$refs['sportsGuess'])
      this.$refs['sportsGuess'].initSportsData()
    }
    if(this.comName == 'answer' && this.$refs['answer']){
      this.$refs['answer'].init()
    }
    if(this.comName == 'vote'){
      if(this.comData!=null){
        let data =  this.comData
				proxyShareFun(data.settings.title||data.settings.desc,data.settings.image,data.settings.desc,window.location.href)
      }
    }
  },
}
</script>

<style>
</style>